package tr.edu.boun.phys.springmassmodel;

public class Mass {
	
	private double m;
	private double b;
	
	private Vector2D r;
	private Vector2D v;
	private Vector2D a;
	
	private Vector2D r0;
	private Vector2D v0;
	
	private int constraint;
	
	public static final int NO_CONSTRAINT = 0;
	public static final int Y_ONLY = 1;
	public static final int X_ONLY = 2;
	public static final int NO_FREEDOM = 3;
	
	//private int ID;
	
	public Mass(double m, Vector2D r0, Vector2D v0) {
		this.m = m;
		this.r0 = (Vector2D)r0.clone();
		this.v0 = (Vector2D)v0.clone();				
		
		this.r = (Vector2D)this.r0.clone();
		this.v = (Vector2D)this.v0.clone();
		
		this.a  = new Vector2D(0.0, 0.0);
		this.constraint = NO_CONSTRAINT;
		this.b = 0.0001;		
	}
	
	public void applyForce(Vector2D f, double dt) {		
		a.x = (f.x - b*v.x) / m;
		a.y = (f.y - b*v.y) / m;
		
		v.x = v.x + a.x * dt;
		v.y = v.y + a.y * dt;
		
		r.x = r.x + v.x * dt;
		r.y = r.y + v.y * dt;
	}
	
	public Vector2D getLocation() {
		return r;
	}
	
	public Vector2D getInitialLocation() {
		return r0;
	}
	
	public double getM() {
		return m;
	}
	
	public void setM(double m) {
		this.m = m;
	}
	
	public double getB() {
		return b;
	}
	
	public void setB(double b) {
		this.b = b;
	}
	
	public void setConstraint(int constraintType) {
		constraint = constraintType;
		switch(constraintType) {
		case NO_CONSTRAINT:
			break;
		case X_ONLY:
			v.y = 0.0;
			break;			
		case Y_ONLY:
			v.x = 0.0;
			break;
		case NO_FREEDOM:
			v.x = v.y = 0.0;
			break;
		}
	}
	
	public int getConstraint() {
		return constraint;
	}
	
	public void move(Vector2D location) {
		this.r.x = location.x;
		this.r.y = location.y;
	}
	
	public void setV(Vector2D v) {
		this.v.x = v.x;
		this.v.y = v.y;
	}
}


